package dao.search;

import util.C3p0Util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class RoomMessageSearchDao {
    //统计当前入住房间的总人数
    public void AllPeople(){

        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        int count = 0;

        String sql = "select count(s_r_number) from t_student";


        try {

            conn = C3p0Util.getConnection();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()) {
                count = rs.getInt(1);
                System.out.println("当前入住房间的总人数是：" + count);
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
    //房间数统计
    public void AllRoom(){

        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        int count = 0;

        String sql = "select count(r_number) from t_room";


        try {

            conn = C3p0Util.getConnection();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()) {
                count = rs.getInt(1);
                System.out.println("房间总数是：" + count);
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    //房间的可住人数总计
    public void AllRoomPeople(){

        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        int count = 0;

        String sql = "select count(r_number) from t_room";


        try {

            conn = C3p0Util.getConnection();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()) {
                count = rs.getInt(1);
                System.out.println("房间的可住人数总计：" + count*4);
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    public static void main(String[] args) {
        RoomMessageSearchDao rmsd = new RoomMessageSearchDao();
        rmsd.AllRoomPeople();

    }
}
